package com.wva.redis;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;

/**
 * @Author: hong
 * @Date: 2025/1/28 18:52:52
 */
public class RedissonAutoConfigure {
    @Value("${spring.redis.host}")
    private String host;

    @Value("${spring.redis.port}")
    private Integer port;

    @Value("${spring.redis.database}")
    private Integer database;

    // @Value("${spring.redis.password}")
    // private String password;

    @Bean
    RedissonClient redissonClient() {
        Config config = new Config();
        config
                .useSingleServer() //support multi-server mode
                .setAddress(String.format("redis://%s:%d", host, port))
                .setDatabase(database);
        // .setPassword() //if have password
        return Redisson.create(config);
    }
}
